package baiwa.rta.action.common;

import static com.opensymphony.xwork2.Action.SUCCESS;

import java.util.LinkedHashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;


import baiwa.rta.action.BaseAction;
import baiwa.rta.model.TowerModel;
import baiwa.rta.service.ComboboxService;

@Namespaces(value = { @Namespace("/combo") })
@ParentPackage(value = "json-default")
public class ComboboxAction extends BaseAction {

	private static final Logger logger = Logger.getLogger(ComboboxAction.class);
	private LinkedHashMap<String, Object> jsonData = new LinkedHashMap<>();
	private ComboboxService service = lookupBean(ComboboxService.class, "ComboboxService");
	private TowerModel tower ;
	
//	public String execute() throws Exception {
//		logger.info("ComboboxAction Home.");
//		return SUCCESS;
//	}

	@Action(value = "getTower", results = { @Result(name = SUCCESS, type = "json", params = { "root", "jsonData" }) })
	public String getTowerCombo() throws Exception {
		logger.info("ComboboxAction getTowerCombo>>>> "+tower);
		
		jsonData.clear();
		
		List<TowerModel> list = service.getTowerModelByCriteria(tower);
		jsonData.put("items", list);
		
		return SUCCESS;
	}
	
//	@Action(value = "getTowerCriteria", results = { @Result(name = SUCCESS, type = "json", params = { "root", "jsonData" }) })
//	public String getTowerCriteria() throws Exception {
//		logger.info("ComboboxAction getFloorByTower>>>> "+getRequest().getParameterMap());
//		
//		jsonData.clear();
//		TowerModel towerModel = new TowerModel();
//		if(getRequest().getParameter("floor")!= null){
//			towerModel.setTower(getRequest().getParameter("floor"));
//		}
//		
//		if(getRequest().getParameter("unit")!= null){
//			towerModel.setUnitNo(getRequest().getParameter("unit"));
//		}
//		
//		if(getRequest().getParameter("address")!= null){
//			towerModel.setAdderss(getRequest().getParameter("address"));
//		}
//		
//		List<TowerModel> list = service.getTower(towerModel);
//		List<SelectBoxView> items = new ArrayList<SelectBoxView>();
//		for (TowerModel m : list) {
//			items.add(new SelectBoxView(p.getProvinceCode(), p.getProvinceName()));
//		}
		
//		items.add(new SelectBoxView("A" , "Tower A"));
//		items.add(new SelectBoxView("B" , "Tower B"));
//		items.add(new SelectBoxView("C" , "Tower C"));
//		items.add(new SelectBoxView("D" , "Tower D"));
		
//		jsonData.put("items", list);
//		
//		return SUCCESS;
//	}

	@JSON(name = "jsonData")
	public LinkedHashMap<String, Object> getJsonData() {
		return jsonData;
	}

	public TowerModel getTower() {
		return tower;
	}

	public void setTower(TowerModel tower) {
		this.tower = tower;
	}



}
